package com.eattravel.service.impl;

import com.eattravel.dto.PageInfoResult;
import com.eattravel.mapper.CommodityMapper;
import com.eattravel.mapper.StoreMapper;
import com.eattravel.pojo.Commodity;
import com.eattravel.pojo.Store;
import com.eattravel.service.StoreService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StoreServiceImpl implements StoreService {

    @Autowired
    StoreMapper storeMapper;

    @Override
    public Store findStoreById(String storeId) {
        Store store = storeMapper.findStoreById(storeId);
        return store;
    }

    @Autowired
    CommodityMapper commodityMapper;

    @Override
    public PageInfoResult<Commodity> selectCommodityByStoreId(PageInfoResult pageParameter, String storeId) {
        //根据传来的分页信息查询数据
        PageHelper.startPage(pageParameter.getCurrPage(), pageParameter.getPageSize());
        //查询商家的商品
        List<Commodity> commodities = commodityMapper.selectCommodityByStoreId(storeId);
        //将查询的数据装入到pageinfo
        PageInfo<Commodity> pageInfo = new PageInfo<Commodity>(commodities);
        // 查询的当前页数据信息
        List<Commodity> empList = pageInfo.getList();
        // 获取查询的总条数
        pageParameter.setTotalSize(pageInfo.getTotal());
        pageParameter.setDataList(empList);
        return pageParameter;
    }
}
